<?php
/**
 * Date: 10/05/11
 * Time: 21:40
 */

class Galerie {
    const mediaNodeID = '1309979115';
    const nodePrefix = 'node_';
    private $_classMedia;

    public function __construct(){
        $this->_classMedia = Base::Load(CLASS_MEDIA);
    }

    public function getGalleryList($nodeID = false, $limit = false){
        if(!$nodeID)
            $nodeID = self::mediaNodeID;
        $data = array();
        $n = 0;
        foreach($this->_classMedia->get(self::nodePrefix.$nodeID, true, false) as $key => $child){
            if(!$limit || $n < $limit){
            $data[$key]['data'] = $child;
            $data[$key]['child'] = $this->_classMedia->get($child->attr->id, true, false);
            $n++;
            }
            else
                break;
        }

        return (object)$data;
    }

    public function getGallery($galleryID){
        return $this->_classMedia->get(self::nodePrefix.$galleryID, true, false);
    }

    public function getGalleryName($galleryID){
        $data = $this->getGalleryList();
        foreach($data as $g){
            if($g['data']->attr->id == self::nodePrefix.$galleryID){
                $myTitle = $g['data']->data;
                break;
            }
        }
        return $myTitle;
    }
    
}
